#include "LoadState.h"
#include "../Bitmap Font/BitmapFont.h"
#include "MainMenuState.h"
#include "../DeadlyShadowsLastHope/Game.h"
#include "GameplayState.h"
#include "LevelState.h"

CLoadState* CLoadState::GetInstance(void)
{
	static CLoadState s_Instance;
	return &s_Instance;
}

CLoadState::CLoadState(void)
{
	m_nLoad					= -1;
}

CLoadState::~CLoadState(void) { }

void CLoadState::Enter(void)
{
//setup the state
	m_pD3D	= CSGD_Direct3D::GetInstance();
	m_pTM	= CSGD_TextureManager::GetInstance();
	m_pDI	= CSGD_DirectInput::GetInstance();
	m_pXA	= CSGD_XAudio2::GetInstance();
	m_pTM	= CSGD_TextureManager::GetInstance();

	m_nLoad = m_pTM->LoadTexture(	_T("../resources/graphics/load_menu.png")/*, D3DCOLOR_XRGB(0, 0, 0)*/ );
}

void CLoadState::Exit(void)
{
	if (this->m_nLoad != -1)
	{
		this->m_pTM->UnloadTexture(this->m_nLoad);
		this->m_nLoad = -1;
	}
}

void CLoadState::Update(float fElapsedTime) { }

void CLoadState::Render(void)
{
	m_pTM->Draw(m_nLoad, 0, 0, 0.8f, 0.6f, nullptr, 0, 0, 0); 
	m_pD3D->GetSprite()->Flush();
}

bool CLoadState::Input(void)
{
	if (m_pDI->KeyPressed(DIK_ESCAPE))
	{
		CGame::GetInstance()->AddState(CMainMenuState::GetInstance());
		CGame::GetInstance()->RemoveState(this);
	}
	if (m_pDI->KeyPressed(DIK_RETURN))
	{
			CGame::GetInstance()->RemoveState(this);
			CGame::GetInstance()->AddState(CLevelState::GetInstance());
			CGame::GetInstance()->AddState(CGameplayState::GetInstance());
			CGameplayState::GetInstance()->LoadGame("game.txt");
			//CJM - NEED to FIX LOADING 

	}
	return true;
}